#!/usr/bin/with-contenv sh

set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error.

TITLE="$1"
MSG="$2"
LEVEL="$3"

YAD="$(which yad)"
if [ "${YAD:-UNSET}" != "UNSET" ]; then
    XDG_BASE="$(mktemp -d)"

    export XDG_DATA_HOME="$XDG_BASE/xdg/data"
    export XDG_CONFIG_HOME="$XDG_BASE/xdg/config"
    export XDG_CACHE_HOME="$XDG_BASE/xdg/cache"

    yad \
        --fixed \
        --center \
        --title "$APP_NAME" \
        --window-icon /opt/novnc/images/icons/master_icon.png \
        --borders 10 \
        --image dialog-warning \
        --image-on-top \
        --text "<b>$TITLE</b>" \
        --form \
        --field "$MSG:LBL" \
        --button=gtk-ok:0 > /dev/null || true

    rm -r "$XDG_BASE"
fi

# vim: set ft=sh :
